<?php
/**
 *
 * UCModMedalInterface class file
 *
 * @category   UC
 * @author     刘海涛 <liuhaitao01@snda.com>
 * @copyright  1997-2010 SDO Group
 * @version    Release: 1.0.0
 * @link       http://www.sdo.com
 * @license    http://www.sdo.com
 */
require_once(dirname(__FILE__).'/UCModMedal.php');
require_once(dirname(__FILE__).'/../../config/UCConfMacro.php');
require_once(dirname(__FILE__).'/../../libraries/UCLibCache.php');
require_once(dirname(__FILE__).'/../../models/invite/UCModInvite.php');
require_once(dirname(__FILE__).'/../../models/user/UCModUserInfo.php');
require_once(dirname(__FILE__).'/../../models/user/UCModUserStatistics.php');
require_once(dirname(__FILE__).'/../../models/user/UCModActiveUser.php');
require_once(dirname(__FILE__).'/../../models/relation/UCModRelation.php');
require_once(dirname(__FILE__).'/../../models/feed/UCModFeed.php');
require_once(dirname(__FILE__).'/../../../unified/SDOApiVipService.php');
require_once(dirname(__FILE__).'/../../../statistics/Statistic.inc.php');


class UCModMedalInterface
{
	public static $error_no = 0;

	/**
	 * 检查用户是否完成新手任务
	 * @param	string	$img	勋章头像地址
	 * @param	string	$type	's' 小 | 'm2' 中小 | 'm' 中 | 'b' 大 | 'd' 小图灰显 | 'md' 中图灰显  
	 * @return	mix				error:false 正确返回数量
	 *
	 */
	static function getMedalAvatar($img,$type)
	{
		if(empty($img) || empty($type))
		{
			self::$error_no = UCConfMedal::MEDAL_ERROR_PARAM;
			return false;
		}
		return Yii::app()->params['static_domain'].'/images/medal/'.$type.'_'.$img;
	}

	/**
	 * 检查用户是否完成新手任务
	 * @param	string	$uid	用户ID
	 * @return	mix				error:false 正确返回数量
	 *
	 */
	static public function checkFreshTask($uid)
	{
		if(empty($uid))
		{
			self::$error_no = UCConfMedal::MEDAL_ERROR_PARAM;
			return false;
		}

		$o_user = UCModUserInfo::getUser($uid);
		if(!$o_user->getValue(USERINFO_AVATAR_VERSION))
		{
			$ar_ret['result'] = 1;
		}
		else
		{
			$ar_ret['result'] = 2;
		}
		return $ar_ret;
	}

	/**
	 * 获取用户连续登录天数
	 * @param	string	$uid	用户ID
	 * @return	mix				error:false 正确返回数量
	 *
	 */
	static public function checkLastLogin($uid)
	{
		if(empty($uid))
		{
			self::$error_no = UCConfMedal::MEDAL_ERROR_PARAM;
			return false;
		}
		$o_user_stat = new UCModUserStatistics($uid);
		if($o_user_stat->getValue(UC_STAT_HIT_7_DAYS))
		{
			$ar_ret['result'] = 2;
		}
		else
		{
			$num = $o_user_stat->getValue(UC_STAT_CONTINUOUS_LOGIN_DAYS);
			$ar_ret = self::_retFunc(UCConfMedal::MEDAL_USER_LAST_LOGIN_DAYS,$num);
		}
		return $ar_ret;
	}

	/**
	 * 获取用户累计登录天数
	 * @param	string	$uid	用户ID
	 * @return	mix				error:false 正确返回数量
	 *
	 */
	static public function getTotalLoginDay($uid)
	{
		if(empty($uid))
		{
			self::$error_no = UCConfMedal::MEDAL_ERROR_PARAM;
			return false;
		}
		$o_user_stat = new UCModUserStatistics($uid);
		return $o_user_stat->getValue(UC_STAT_LOGIN_DAYS);
	}
	

	/**
	 * 获取用户固定好友数量
	 * @param	string	$uid	用户ID
	 * @param	int		$type	UCConfMedal::MEDAL_FRIEND_INTER | UCConfMedal::MEDAL_FRIEND_SINGEL
	 * @return	mix				error:false 正确返回数量
	 *
	 */
	static public function getHaveFriends($uid,$type=UCConfMedal::MEDAL_FRIEND_INTER)
	{
		if(empty($uid))
		{
			self::$error_no = UCConfMedal::MEDAL_ERROR_PARAM;
			return false;
		}
		$o_relation = new UCModRelation($uid);
		if(UCConfMedal::MEDAL_FRIEND_SINGEL==$type)
		{
			$i_count = $o_relation->getRelationFollowCount();
		}
		else
		{
			$i_count = $o_relation->getBiRelationCount();
		}
		return $i_count;
	}

	/**
	 * 获取用户粉丝数量
	 * @param	string	$uid	用户ID
	 * @return	mix				error:false 正确返回数量
	 *
	 */
	static public function getFansNum($uid)
	{
		if(empty($uid))
		{
			self::$error_no = UCConfMedal::MEDAL_ERROR_PARAM;
			return false;
		}
		$o_relation = new UCModRelation($uid);
		return $o_relation->getRelationReverseCount();
	}
	
	/**
	 * 获取用户邀请好友数量
	 * @param	string	$uid	用户ID
	 * @return	mix				error:false 正确返回数量
	 *
	 */
	static public function getInviteFriendsNum($uid)
	{
		if(empty($uid))
		{
			self::$error_no = UCConfMedal::MEDAL_ERROR_PARAM;
			return false;
		}
		$o_invite = new UCModInvite();
		$ar_invite = $o_invite->getInviteRequestInfo($uid, array('ticket_status' => INVITE_OVER), true);
		return $ar_invite[0]['num'];
	}

	/**
	 * 获取用户所发推他数量
	 * @param	string	$uid	用户ID
	 * @return	mix				error:false 正确返回数量
	 *
	 */
	static public function getTwitterNum($uid)
	{
		if(empty($uid))
		{
			self::$error_no = UCConfMedal::MEDAL_ERROR_PARAM;
			return false;
		}
		$o_statis = new UCModUserStatistics($uid);
		$num = $o_statis->getValue(UC_STAT_MOOD_MEDAL_CNT);
		if(empty($num))
		{
			$num = $o_statis->getValue(UC_STAT_MOOD_CNT);
		}
		return $num;
	}

	/**
	 * 获取用户推他被转发次数
	 * @param	string	$uid	用户ID
	 * @return	mix				error:false 正确返回数量
	 *
	 */
	static public function getRetwitterNum($uid)
	{
		if(empty($uid))
		{
			self::$error_no = UCConfMedal::MEDAL_ERROR_PARAM;
			return false;
		}
		$o_statis = new UCModUserStatistics($uid);
		return $o_statis->getValue(UC_STAT_MOOD_RETWITTER_CNT);
	}
	
	/**
	 * 检查勋章记录是否存在 
	 * @param	string	$uid		用户ID
	 * @param	int		$medal_id	勋章ID
	 * @return						false:error | 勋章记录流水号	
	 *
	 */
	static public function checkUserMedal($uid,$medal_id)
	{
		$ar_ret = self::getDoneList($uid);
		if(false===$ar_ret)
		{
			self::$error_no = $o_medal->error_no;
			return false;
		}
		return array('um_id'=>$ar_ret['list'][$medal_id]['um_id'],'medal_status'=>$ar_ret['list'][$medal_id]['medal_status']);
	}
	
	/**
	 * 删除用户勋章 
	 * @param	string	$uid		用户ID
	 * @param	int		$medal_id	勋章ID
	 * @return	mix					false:error 1:已经完成不入库 2：第一次完成入库	
	 *
	 */
	static public function delUserMedal($uid,$medal_id)
	{
		if(empty($uid) || empty($medal_id))
		{
			self::$error_no = UCConfMedal::MEDAL_ERROR_PARAM;
			return false;
		}

		if(false===self::updateUserMedal($uid,$medal_id,array('medal_status'=>UCConfMedal::MEDAL_USER_STATUS_GET)))
		{
			self::$error_no = $o_medal->error_no;
			return false;
		}

		$o_cache	= new UCLibCache(UCConfMedal::MEDAL_MEMCACHE_FLAG); 
		$s_key		= UCConfMedal::MEDAL_MEMCACHE_KEY_USER_LIST.$uid;
		if(false===$o_cache->delete($s_key))
		{
			self::$error_no = UCConfMedal::MEDAL_ERROR_MEMCACHE;
			return false;
		}
		return true;
	}

	/**
	 * 增加勋章记录 
	 * @param	string	$uid		用户ID
	 * @param	int		$medal_id	勋章ID
	 * @return	mix					false:error 1:已经完成不入库 2：第一次完成入库	
	 *
	 */
	static public function addUserMedal($uid,$medal_id)
	{
		if(empty($uid) || empty($medal_id))
		{
			self::$error_no = UCConfMedal::MEDAL_ERROR_PARAM;
			return false;
		}

		$ar_ret = self::checkMedalById($uid,$medal_id);
		if(false===$ar_ret)
		{
			return false;
		}
		
		if(2==$ar_ret['result'])
		{	
			$status = UCConfMedal::MEDAL_USER_STATUS_DONEANDHAVE;
		}
		elseif(1==$ar_ret['result'])
		{
			$status = UCConfMedal::MEDAL_USER_STATUS_GET;
		}

		$ar_tmp = self::checkUserMedal($uid,$medal_id);
		if(false===$ar_tmp)
		{
			return false;
		}

		
		$o_medal = new UCModMedal($uid);
		if(!empty($ar_tmp['um_id']))
		{
			if($status!=$ar_tmp['medal_status'])
			{
				if(false===$o_medal->updateMedalInfo($ar_tmp['um_id'],array('medal_status'=>$status)))
				{
					self::$error_no = $o_medal->error_no;
					return false;
				}
			}
		}
		else
		{
			$ar_tmp['um_id'] = $o_medal->addMedal(array('medal_id' => $medal_id,'medal_status' => $status));
			if(false===$um_id)
			{
				self::$error_no = $o_medal->error_no;
				return false;
			}
			if(UCConfMedal::MEDAL_USER_STATUS_GET==$status)
			{
				UCLibStat::action(UCConfStat::STAT_MEDAL_APPLY);
				UCLibStat::statex(UCConfStat::STAT_MEDAL_APPLY_USER,$uid);
			}
		}

		if($status!=$ar_tmp['medal_status'])
		{
			if(!self::_doAfterMedalAction($uid,$ar_tmp['um_id'],$medal_id,$status))
			{
				return false;
			}
		}
		return $ar_ret;
	}

	/**
	 * 修改勋章记录 
	 * @param	string	$uid		用户ID
	 * @param	int		$medal_id	勋章ID
	 * @param	array	$ar_param	array(	'medal_status'	=> '勋章状态',
											'medal_limit'	=> '勋章获取限制',
										 )
	 * @return	bool
	 *
	 */
	static public function updateUserMedal($uid,$medal_id,$ar_param)
	{
		if(empty($uid) || empty($medal_id))
		{
			self::$error_no = UCConfMedal::MEDAL_ERROR_PARAM;
			return false;
		}

		$ar_tmp = self::checkUserMedal($uid,$medal_id);
		if(false===$ar_tmp['um_id'])
		{
			return false;
		}
		if(empty($ar_tmp['um_id']))
		{
			self::$error_no = UCConfMedal::MEDAL_ERROR_ILLEGAL;
			return false;
		}
		
		if($ar_param['medal_status']!=$ar_tmp['medal_status'])
		{
			$o_medal = new UCModMedal($uid);
			if(false===$o_medal->updateMedalInfo($ar_tmp['um_id'],$ar_param))
			{
				self::$error_no = $o_medal->error_no;
				return false;
			}
			if(!self::_doAfterMedalAction($uid,$ar_tmp['um_id'],$medal_id,$ar_param['medal_status']))
			{
				return false;
			}
		}
		return true;
	}

	private function _doAfterMedalAction($uid,$um_id,$medal_id,$status)
	{
		$o_cache	= new UCLibCache(UCConfMedal::MEDAL_MEMCACHE_FLAG,false); 
		$s_key		= UCConfMedal::MEDAL_MEMCACHE_KEY_USER_LIST.$uid;
		if($s_ret=$o_cache->read($s_key))
		{
			$ar_ret = unserialize($s_ret);
			$ar_ret['list'][$medal_id]['um_id'] = $um_id;
			$ar_ret['list'][$medal_id]['medal_status'] = $status;
			$ar_ret['list'][$medal_id]['modify_time'] = date('Y-m-d h:i:s');
			if(UCConfMedal::MEDAL_USER_STATUS_DONEANDHAVE==$status)
			{
				$ar_ret['done_count'] += 1;
			}
			$o_cache->write($s_key, serialize($ar_ret), UCConfMedal::MEDAL_MEMCACHE_USER_LIST_EXPIRE); 
		}
		
		if(UCConfMedal::MEDAL_USER_STATUS_DONEANDHAVE==$status)
		{
			//勋章相关统计入库
			UCLibStat::action(UCConfStat::STAT_MEDAL_GET);
			UCLibStat::statex(UCConfStat::STAT_MEDAL_GET_USER,$uid.'|'.UCConfMedal::$ar_type_info[UCConfMedal::$ar_medal_info[$medal_id]['type']].'|'.UCConfMedal::$ar_medal_info[$medal_id]['name']);
			
			$s_key		= UCConfMedal::MEDAL_MEMCACHE_KEY_FEED;
			$s_ret = $o_cache->read($s_key);
			if(empty($s_ret))
			{
				$ar_tmp['count'] = 0;
				$ar_tmp['list'] = array();
			}
			else
			{
				$ar_tmp = unserialize($s_ret);
			}
			$o_user = UCModUserInfo::getUser($uid);
			$ar_push['user_id'] = $uid;
			$ar_push['url'] = get_user_home_url($uid);
			$ar_push['medal_name'] = UCConfMedal::$ar_medal_info[$medal_id]['name'];
			$ar_push['m_desc'] = UCConfMedal::$ar_medal_info[$medal_id]['m_desc'];
			$ar_push['medal_img'] = UCConfMedal::$ar_medal_info[$medal_id]['img'];
			if($ar_tmp['count']<UCConfMedal::MEDAL_FEED_LIST_COUNT)
			{
				$ar_tmp['count'] += 1;
				array_unshift($ar_tmp['list'],$ar_push);
			}
			else
			{
				array_pop($ar_tmp['list']);
				array_unshift($ar_tmp['list'],$ar_push);
			}
			$o_cache->write($s_key, serialize($ar_tmp), UCConfMedal::MEDAL_MEMCACHE_FEED_EXPIRE); 
			$o_statis		= new UCModUserStatistics($uid); 
			if(!$o_statis->increaseValue(UC_STAT_MODAL_CNT))
			{
				self::$error_no = UCConfMedal::MEDAL_ERROR_INTERFACE;
				return false;
			}

			//勋章动态入库
			$o_feed	= new UCModFeed($uid);
			$ar_feed =	array(	'activityType'		=>	UCConfFeed::FEED_TYPE_MEDAL,
								'objectId'			=>	$um_id,
								'medalId'			=>	$medal_id,
								'medalName'			=>	UCConfMedal::$ar_medal_info[$medal_id]['name'],
								'medalIcon'			=>	self::getMedalAvatar(UCConfMedal::$ar_medal_info[$medal_id]['img'],'m2'),
								'reviewable'		=>	0,
							);
			$o_feed->addOneFeed($ar_feed);
		}
		$o_cache->close();
		return true;
	}

	/**
	 * 获取好友勋章列表排行
	 * @param	string	$uid		用户ID
	 * @param	int		$count		当前完成勋章数量
	 * @param	int		$num		获取好友列表长度
	 * @return	array				好友勋章列表凡会数组
	 *
	 */
	static public function getFriendsMedalList($uid,$count=0)
	{
		if(empty($uid))
		{
			self::$error_no = UCConfMedal::MEDAL_ERROR_PARAM;
			return false;
		}
		
		$o_cache	= new UCLibCache(UCConfMedal::MEDAL_MEMCACHE_FLAG); 
		$s_key		= UCConfMedal::MEDAL_MEMCACHE_KEY_FRIEND_BILLBORD.$uid;
		if(!$s_ret=$o_cache->read($s_key))
		{
			$o_relation = new UCModRelation($uid);
			if(!$ar_friends=$o_relation->getRelationFollow(0,10000))
			{
				self::$error_no = UCConfMedal::MEDAL_ERROR_INTERFACE;
				return false;
			}

			$o_static = new UCModUserStatistics($uid);
			$ar_tmp[$uid] = $o_static->getValue(UC_STAT_MODAL_CNT);
			$ids[] = $uid;  
			if($ar_friends['totalResults']>0)
			{
				foreach($ar_friends['entry'] as $friend)
				{
					$o_static = new UCModUserStatistics($friend['fsdid']);
					$ar_tmp[$friend['fsdid']] = $o_static->getValue(UC_STAT_MODAL_CNT);
					$ids[] = $friend['fsdid']; 
				}
				arsort($ar_tmp);			 
			}
			
			if(!empty($ar_tmp))
			{
				$ar_ret['order'] = array_search($uid,array_keys($ar_tmp)) + 1;
			}
			
			$ar_user = UCModUserInfo::getUserInfos($ids, array(USERINFO_NICKNAME,USERINFO_AVATAR_30));
			$i = 0;
			foreach($ar_tmp as $key=>$value)
			{
				$i++;
				$o_userinfo = UCModUserInfo::getUser($key);
				$ar_foreach['user_id'] = $key;
				$ar_foreach['count'] = $value;
				$ar_foreach['order'] = $i;
				$ar_foreach['nickname'] = $ar_user[$ar_foreach['user_id']][USERINFO_NICKNAME];
				$ar_foreach['nickname'] = $ar_foreach['nickname'] ? $ar_foreach['nickname'] : $ar_foreach['user_id'];
				$ar_foreach['avatar'] = $ar_user[$ar_foreach['user_id']][USERINFO_AVATAR_30];
				$ar_foreach['url'] = Yii::app()->urlManager->createUrl('/home/badge/',array('home'=>$key));
				$ar_ret['list'][$key] = $ar_foreach;
				if($i>=UCConfMedal::MEDAL_FRIENDS_LIST_CACHE_NUM)
				{
					break;
				}
			}
			$o_cache->write($s_key, serialize($ar_ret), UCConfMedal::MEDAL_MEMCACHE_FRIEND_BILLBORD_EXPIRE);
		}
		else
		{
			$ar_ret = unserialize($s_ret);
		}

		if($count)
		{	
			if(!empty($ar_ret['list']))
			{
				$ar_ret['list'] = array_slice($ar_ret['list'],0,$count);
			}
		}
		return $ar_ret;
	}
	
	
	public function updateMedalList($uid,$num)
	{
		$medal_friends_list = self::getFriendsMedalList($uid);
		if(false===$medal_friends_list)
		{
			return false;
		}
		if(!array_key_exists($uid,$medal_friends_list['list']))
		{
			$o_userinfo = UCModUserInfo::getUser($uid);
			$ar_user['user_id'] = $uid;
			$ar_user['count'] = $num;
			$ar_user['order'] = UCConfMedal::MEDAL_FRIENDS_LIST_CACHE_NUM + 1;
			$ar_user['nickname'] = $o_userinfo->getName();
			$ar_user['nickname'] = $ar_user['nickname'] ? $ar_user['nickname'] : $ar_user['user_id'];
			$ar_user['avatar'] = $o_userinfo->getAvatar(USERINFO_AVATAR_30);
			$ar_user['url'] = Yii::app()->urlManager->createUrl('/home/badge/',array('home'=>$key));
			$medal_friends_list['list'][$uid] = $ar_user;
		}
		else
		{
			$medal_friends_list['list'][$uid]['count'] = $num;
		}

		$ar_ret = sortByMultiCols($medal_friends_list['list'],array('count'=>SORT_DESC));
		$i = 0;
		foreach($ar_ret as $key=>$value)
		{
			$i++;
			$value['order'] = $i;
			$ar_tmp[$value['user_id']] = $value;
		}
		if((UCConfMedal::MEDAL_FRIENDS_LIST_CACHE_NUM+1)==$ar_tmp[$uid]['order'])
		{
			unset($ar_tmp[$uid]);
			$medal_friends_list['order'] = mt_rand(UCConfMedal::MEDAL_FRIENDS_LIST_CACHE_NUM+1,$medal_friends_list['order']);
		}
		else
		{
			$medal_friends_list['order'] = $ar_tmp[$uid]['order'];
		}
		$medal_friends_list['list'] = $ar_tmp;
		$o_cache	= new UCLibCache(UCConfMedal::MEDAL_MEMCACHE_FLAG); 
		$s_key		= UCConfMedal::MEDAL_MEMCACHE_KEY_FRIEND_BILLBORD.$uid;
		$o_cache->write($s_key, serialize($medal_friends_list), UCConfMedal::MEDAL_MEMCACHE_FRIEND_BILLBORD_EXPIRE);
		$medal_friends_list['list'] = array_slice($medal_friends_list['list'],0,10);
		return $medal_friends_list;
	}

	public function getDoneList($uid)
	{
		if(empty($uid))
		{
			self::$error_no = UCConfMedal::MEDAL_ERROR_PARAM;
			return false;
		}
		
		$o_cache	= new UCLibCache(UCConfMedal::MEDAL_MEMCACHE_FLAG); 
		$s_key		= UCConfMedal::MEDAL_MEMCACHE_KEY_USER_LIST.$uid;
		if(!$s_ret=$o_cache->read($s_key))
		{
			$o_medal = new UCModMedal($uid);
			$ar_medals = $o_medal->getAllMedal(UCConfMedal::MEDAL_USER_STATUS_NOGET);
			$num = 0;
			$ar_ret['list'] = array();
			if(!empty($ar_medals))
			{
				foreach($ar_medals as $ar_medal)
				{
					if(UCConfMedal::MEDAL_USER_STATUS_DONEANDHAVE==$ar_medal['medal_status'])
					{
						$num++;
					}
					$ar_ret['list'][$ar_medal['medal_id']] = array('um_id'=>$ar_medal['um_id'],'medal_status'=>$ar_medal['medal_status'],'modify_time'=>$ar_medal['modify_time']);
				}
			}
			$ar_ret['total_count'] = count(UCConfMedal::$ar_medal_info);
			$ar_ret['done_count'] = $num;
			$o_cache->write($s_key, serialize($ar_ret), UCConfMedal::MEDAL_MEMCACHE_USER_LIST_EXPIRE); 
		}
		else
		{
			$ar_ret = unserialize($s_ret);
		}
		return $ar_ret;
	}

	/**
	 * 获取用户勋章详细信息
	 * @param	string	$uid		用户ID
	 * @return	array				勋章列表完成度数组
	 *
	 */
	static public function getUserMedalList($uid)
	{
		$ar_ret = self::getDoneList($uid);
		if(false===$ar_ret)
		{
			return false;
		}
		
		$ar_medal_list['list'] = UCConfMedal::$ar_medal_info;
		if(!empty($ar_ret['list']))
		{
			foreach($ar_ret['list'] as $key=>$value)
			{
				$ar_medal_list['list'][$key]['medal_status'] = $value['medal_status'];
				$ar_medal_list['list'][$key]['modify_time'] = $value['modify_time'];
			}
		}
		$ar_medal_list['total_count'] = $ar_ret['total_count'];
		$ar_medal_list['done_count'] = $ar_ret['done_count'];
		
		return $ar_medal_list;
	}

	/**
	 * 获取用户已经完成勋章信息
	 * @param	string		$uid		用户UID
	 * @return	mix						获取用户已经完成勋章信息 	
	 *
	 */
	static public function getDoneMedal($uid)
	{
		$ar_ret = self::getDoneList($uid);
		$ar_medal_list = array();
		if(!empty($ar_ret['list']))
		{
			foreach($ar_ret['list'] as $key=>$value)
			{
				if(UCConfMedal::MEDAL_USER_STATUS_DONEANDHAVE==$value['medal_status'])
				{
					$ar_tmp = array();
					$ar_tmp['name'] = UCConfMedal::$ar_medal_info[$key]['name'];
					$ar_tmp['icon_b'] = self::getMedalAvatar(UCConfMedal::$ar_medal_info[$key]['img'],'b');
					$ar_tmp['icon_m'] = self::getMedalAvatar(UCConfMedal::$ar_medal_info[$key]['img'],'m');
					$ar_tmp['icon_s'] = self::getMedalAvatar(UCConfMedal::$ar_medal_info[$key]['img'],'s');
					if(UCConfMedal::$ar_medal_info[$key]['url'])
					{
						$ar_tmp['url'] = UCConfMedal::$ar_medal_info[$key]['url'];
					}
					else
					{
						$ar_tmp['url'] = UC_CONF_UC_DOMAIN.'/medal';
					}
					$ar_medal_list[] = $ar_tmp;
				}
			}
		}
		return $ar_medal_list;
	}

	/**
	 * 获取其它用户右侧勋章信息
	 * @param	string		$uid		用户UID
	 * @param	string		$mine		自己UID
	 * @return	mix						获取其它用户右侧勋章信息 	
	 *
	 */
	static public function getDoneMedalOtherUser($uid,$mine)
	{
		$ar_ret = self::getDoneList($uid);
		$ar_medal_list['list'] = array();
		if(!empty($ar_ret['list']))
		{
			foreach($ar_ret['list'] as $key=>$value)
			{
				if(UCConfMedal::MEDAL_USER_STATUS_DONEANDHAVE==$value['medal_status'])
				{
					$ar_medal_list['list'][$key] = UCConfMedal::$ar_medal_info[$key];
					$ar_medal_list['list'][$key]['medal_status'] = $value['medal_status'];
					$ar_medal_list['list'][$key]['modify_time'] = $value['modify_time'];
				}
			}
			if($uid==$mine)
			{
				$ar_medal_list['self'] = 1;
			}
			if(!empty($ar_medal_list['list']))
			{
				$ar_mine = self::getDoneList($mine);
				if(!empty($ar_mine['list']))
				{
					foreach($ar_mine['list'] as $key=>$value)
					{
						if(UCConfMedal::MEDAL_USER_STATUS_DONEANDHAVE==$value['medal_status'])
						{
							if(array_key_exists($key,$ar_medal_list['list']))
							{
								$ar_medal_list['list'][$key]['my_time'] = $value['modify_time'];
								$ar_medal_list['list'][$key]['my_done'] = 1;
							}
						}
					}
				}
			}
		}

		$ar_medal_list['total_count'] = $ar_ret['total_count'];
		$ar_medal_list['done_count'] = $ar_ret['done_count'];
		return $ar_medal_list;
	}

	/**
	 * 获取主页头像信息跟随勋章信息
	 * @param	string	$uid		用户ID
	 * @return	string 				用“,”隔开的字符串
	 *
	 */
	static public function getUserAllMedal($uid,$count=0)
	{
		$ar_ret = self::getDoneList($uid);
		if(false===$ar_ret)
		{
			return false;
		}
		if(empty($count))
		{
			$ar_medal_list = UCConfMedal::$ar_medal_info;
			foreach($ar_ret['list'] as $key=>$value)
			{
				$ar_medal_list['list'][$ar_medal['medal_id']]['medal_status'] = $value['medal_status'];
			}
		}
		else
		{
			$num = 0;
			$ar_medal_list['list'] = array();
			foreach($ar_ret['list'] as $key=>$value)
			{
				if(UCConfMedal::MEDAL_USER_STATUS_DONEANDHAVE==$value['medal_status'])
				{
					$num++;
					$ar_medal_list['list'][$key] = UCConfMedal::$ar_medal_info[$key];
					$ar_medal_list['list'][$key]['medal_status'] = $value['medal_status'];
					$ar_medal_list['list'][$key]['modify_time'] = $value['modify_time'];
					if($num>=$count)
					{
						break;
					}
				}
			}
			if($num<$count)
			{
				foreach(UCConfMedal::$ar_medal_site as $value)
				{
					if(!array_key_exists($value, $ar_medal_list['list']))
					{
						$num++;
						$ar_medal_list['list'][$value] = UCConfMedal::$ar_medal_info[$value];
						$ar_medal_list['list'][$value]['medal_status'] = intval($ar_ret['list'][$value]['medal_status']);
						$ar_medal_list['list'][$value]['modify_time'] = $ar_ret['list'][$value]['modify_time'];
						if($num>=$count)
						{
							break;
						}
					}
				}
			}
		}
		$ar_medal_list['total_count'] = $ar_ret['total_count'];
		$ar_medal_list['done_count'] = $ar_ret['done_count'];
		return $ar_medal_list;
	}

	/**
	 * 获取系统最新动态勋章信息
	 * @param	int		$count		获取数量
	 * @return	string 				用“,”隔开的字符串
	 *
	 */
	static public function getMedalFeeds()
	{
		$o_cache	= new UCLibCache(UCConfMedal::MEDAL_MEMCACHE_FLAG); 
		$s_key		= UCConfMedal::MEDAL_MEMCACHE_KEY_FEED;
		if($s_ret=$o_cache->read($s_key))
		{
			$ar_ret = unserialize($s_ret);
			if(!empty($ar_ret['list']))
			{
				foreach($ar_ret['list'] as $user)
				{
					$ids[] = $user['user_id']; 
				}
				$ar_user = UCModUserInfo::getUserInfos($ids, array(USERINFO_NICKNAME));
				foreach($ar_ret['list'] as $key=>$user)
				{
					$nickname = $ar_user[$user['user_id']][USERINFO_NICKNAME];
					$ar_ret['list'][$key]['nickname'] = $nickname ?  $nickname : $user['user_id']; 
				}
			}
		}
		else
		{
			$ar_ret['count'] = 0;
			$ar_ret['list'] = array();
		}
		return $ar_ret;
	}

	/**
	 * 获取查看用户勋章信息
	 * @param	string		$uid		用户UID
	 * @param	string		$mine		自己UID
	 * @return	mix						用户查看他人勋章页输出相关信息 	
	 *
	 */
	static public function getMedalForOtherUser($uid,$mine)
	{
		//获取用户勋章展示列表
		$medal_list = self::getUserMedalList($uid);
		$medal_list_mine = self::getDoneList($mine);
		if(!empty($medal_list_mine['list']))
		{
			foreach($medal_list_mine['list'] as $key=>$value)
			{
				if(UCConfMedal::MEDAL_USER_STATUS_DONEANDHAVE==$value['medal_status'])
				{
					$medal_list['list'][$key]['my_time'] = $value['modify_time'];
					$medal_list['list'][$key]['my_done'] = 1;
				}
			}
		}
		foreach ($medal_list['list'] as $key=>$medal) 
        {
			if(UCConfMedal::MEDAL_USER_STATUS_DONEANDHAVE==$medal['medal_status'])
			{
				$ar_medal[$medal['type']]['done_count'] += 1; 				
			}
			$medal['id'] = $key;
			$ar_medal[$medal['type']]['total_count'] += 1;
			$ar_medal[$medal['type']]['list'][] = $medal;
        }
		
		if(false===$ar_ret)
		{
			return false;
		}
		//获取用户好友勋章展示排行榜
		$medal_friends_list = self::getFriendsMedalList($uid,UCConfMedal::MEDAL_FRIENDS_LIST_NUM);
		if(false===$medal_friends_list)
		{
			return false;
		}
		if($uid==$mine)
		{
			$medal_friends_list['self'] = 1;
		}
		$medal_friends_list['done_count'] = $medal_list['done_count'];
		$medal_friends_list['total_count'] = $medal_list['total_count'];
		return array('medal_list'=>$ar_medal,'billboard'=>$medal_friends_list);
	}
	
	/**
	 * 检查用户勋章是否完成 
	 * @param	string	$uid		用户ID
	 * @param	int		$medal_id	勋章ID
	 * @return	mix					false:error | array('result'=> '1:未完成徽章|2:完成徽章并且入库','param'=>'相关输出辅助信息')
	 *
	 */
	static public function checkMedalById($uid,$medal_id)
	{
		if(empty($uid) || empty($medal_id))
		{
			self::$error_no = UCConfMedal::MEDAL_ERROR_PARAM;
			return false;
		}
		
		$ar_ret = array();
		switch($medal_id)
		{
			case UCConfMedal::MEDAL_ACTIVITY_FRESH:
				$ar_ret = self::checkFreshTask($uid);
				if(1==$ar_ret['result'])
				{
					//$ar_ret['msg'] = sprintf(UCConfMedal::$ar_show_info[$medal_id],$ar_ret['q']);
					$ar_ret['msg'] = UCConfMedal::$ar_show_info[$medal_id];
				}
				break;

			case UCConfMedal::MEDAL_ACTIVITY_FAITH:
				$ar_ret = self::checkLastLogin($uid);
				if(1==$ar_ret['result'])
				{
					$ar_ret['msg'] = sprintf(UCConfMedal::$ar_show_info[$medal_id],$ar_ret['total_count'],($ar_ret['need_count']-$ar_ret['total_count']));
				}
				break;

			case UCConfMedal::MEDAL_ACTIVITY_FANS:
				$num = self::getTotalLoginDay($uid);
				$ar_ret = self::_retFunc(UCConfMedal::MEDAL_USER_TOTAL_LOGIN_DAYS,$num);
				if(1==$ar_ret['result'])
				{
					$ar_ret['msg'] = sprintf(UCConfMedal::$ar_show_info[$medal_id],$ar_ret['total_count'],($ar_ret['need_count']-$ar_ret['total_count']));
				}
				break;

			case UCConfMedal::MEDAL_INVITE_GENERAL:
				$num = self::getInviteFriendsNum($uid);
				$ar_ret = self::_retFunc(UCConfMedal::MEDAL_USER_INVITE_FIVE,$num);
				if(1==$ar_ret['result'])
				{
					$ar_ret['msg'] = sprintf(UCConfMedal::$ar_show_info[$medal_id],($ar_ret['need_count']-$ar_ret['total_count']));
				}
				break;

			case UCConfMedal::MEDAL_INVITE_ENJOY:
				$num = self::getInviteFriendsNum($uid);
				$ar_ret = self::_retFunc(UCConfMedal::MEDAL_USER_INVITE_TEN,$num);
				if(1==$ar_ret['result'])
				{
					$ar_ret['msg'] = sprintf(UCConfMedal::$ar_show_info[$medal_id],($ar_ret['need_count']-$ar_ret['total_count']));
				}
				break;
			
			case UCConfMedal::MEDAL_INVITE_CRAZY:
				$num = self::getInviteFriendsNum($uid);
				$ar_ret = self::_retFunc(UCConfMedal::MEDAL_USER_INVITE_TWENTY,$num);
				if(1==$ar_ret['result'])
				{
					$ar_ret['msg'] = sprintf(UCConfMedal::$ar_show_info[$medal_id],($ar_ret['need_count']-$ar_ret['total_count']));
				}
				break;
			
			case UCConfMedal::MEDAL_FANS_FRIEND:
				$num = self::getHaveFriends($uid);
				$ar_ret = self::_retFunc(UCConfMedal::MEDAL_USER_FANS_TEN,$num);
				if(1==$ar_ret['result'])
				{
					$ar_ret['msg'] = sprintf(UCConfMedal::$ar_show_info[$medal_id],($ar_ret['need_count']-$ar_ret['total_count']));
				}
				break;
			
			case UCConfMedal::MEDAL_FANS_LOVE:
				$num = self::getFansNum($uid);
				$ar_ret = self::_retFunc(UCConfMedal::MEDAL_USER_FANS_FIFTY,$num);
				if(1==$ar_ret['result'])
				{
					$ar_ret['msg'] = sprintf(UCConfMedal::$ar_show_info[$medal_id],($ar_ret['need_count']-$ar_ret['total_count']));
				}
				break;
			
			case UCConfMedal::MEDAL_FANS_STAR:
				$num = self::getFansNum($uid);
				$ar_ret = self::_retFunc(UCConfMedal::MEDAL_USER_FANS_FIVEHUNDRED,$num);
				if(1==$ar_ret['result'])
				{
					$ar_ret['msg'] = sprintf(UCConfMedal::$ar_show_info[$medal_id],($ar_ret['need_count']-$ar_ret['total_count']));
				}
				break;
			
			case UCConfMedal::MEDAL_TWITTER_GROUP:
				$num = self::getTwitterNum($uid);
				$ar_ret = self::_retFunc(UCConfMedal::MEDAL_USER_TWITTER_TEN,$num);
				if(1==$ar_ret['result'])
				{
					$ar_ret['msg'] = sprintf(UCConfMedal::$ar_show_info[$medal_id],($ar_ret['need_count']-$ar_ret['total_count']));
				}
				break;
			
			case UCConfMedal::MEDAL_TWITTER_LEADER:
				$num = self::getTwitterNum($uid);
				$ar_ret = self::_retFunc(UCConfMedal::MEDAL_USER_TWITTER_HUNDRED,$num);
				if(1==$ar_ret['result'])
				{
					$ar_ret['msg'] = sprintf(UCConfMedal::$ar_show_info[$medal_id],($ar_ret['need_count']-$ar_ret['total_count']));
				}
				break;
			
			case UCConfMedal::MEDAL_TWITTER_LOAD:
				$num = self::getRetwitterNum($uid);
				$ar_ret = self::_retFunc(UCConfMedal::MEDAL_USER_TWITTER_FIVEHUNDRED,$num);
				if(1==$ar_ret['result'])
				{
					$ar_ret['msg'] = sprintf(UCConfMedal::$ar_show_info[$medal_id],($ar_ret['need_count']-$ar_ret['total_count']));
				}
				break;

			case UCConfMedal::MEDAL_IDENTITY_GOLD:
				$ar_ret = self::_checkVip($uid,UCConfMedal::MEDAL_USER_IDENTITY_GOLD);
				if(1==$ar_ret['result'])
				{
					$ar_ret['msg'] = sprintf(UCConfMedal::$ar_show_info[$medal_id],UCConfMedal::$ar_medal_info[$medal_id]['name']);
				}
				break;
			
			case UCConfMedal::MEDAL_IDENTITY_RHOD:
				$ar_ret = self::_checkVip($uid,UCConfMedal::MEDAL_USER_IDENTITY_RHOD);
				if(1==$ar_ret['result'])
				{
					$ar_ret['msg'] = sprintf(UCConfMedal::$ar_show_info[$medal_id],UCConfMedal::$ar_medal_info[$medal_id]['name']);
				}
				break;
			
			case UCConfMedal::MEDAL_IDENTITY_DIAMOND:
				$ar_ret = self::_checkVip($uid,UCConfMedal::MEDAL_USER_IDENTITY_DIAMOND);
				if(1==$ar_ret['result'])
				{
					$ar_ret['msg'] = sprintf(UCConfMedal::$ar_show_info[$medal_id],UCConfMedal::$ar_medal_info[$medal_id]['name']);
				}
				break;

			case UCConfMedal::MEDAL_PANDUOLA_COPPER:
				$ar_ret = self::_checkPanduola($uid,0);
	
				if(false===$ar_ret)
				{
					return false;
				}
				if(1==$ar_ret['result'])
				{
					$ar_ret['msg'] = sprintf(UCConfMedal::$ar_show_info[$medal_id],$ar_ret['sub']);
				}
				break;

			case UCConfMedal::MEDAL_PANDUOLA_SILVER:
				$ar_ret = self::_checkPanduola($uid,1);
				if(false===$ar_ret)
				{
					return false;
				}
				if(1==$ar_ret['result'])
				{
					$ar_ret['msg'] = sprintf(UCConfMedal::$ar_show_info[$medal_id],$ar_ret['sub']);
				}
				break;

			case UCConfMedal::MEDAL_PANDUOLA_GOLD:
				$ar_ret = self::_checkPanduola($uid,2);

				if(false===$ar_ret)
				{
					return false;
				}
				if(1==$ar_ret['result'])
				{
					$ar_ret['msg'] = sprintf(UCConfMedal::$ar_show_info[$medal_id],$ar_ret['sub']);
				}
				break;

			case UCConfMedal::MEDAL_PAOPAOYU_1:
				$ar_ret = self::_checkPaopaoyu($uid,2);

				if(false===$ar_ret)
				{
					return false;
				}
				if(1==$ar_ret['result'])
				{
					$ar_ret['msg'] = sprintf(UCConfMedal::$ar_show_info[$medal_id],$ar_ret['level']);
				}
				break;	

			case UCConfMedal::MEDAL_PAOPAOYU_2:
				$ar_ret = self::_checkPaopaoyu($uid,7);

				if(false===$ar_ret)
				{
					return false;
				}
				if(1==$ar_ret['result'])
				{
					$ar_ret['msg'] = sprintf(UCConfMedal::$ar_show_info[$medal_id],$ar_ret['level']);
				}
				break;	

			case UCConfMedal::MEDAL_PAOPAOYU_3:
				$ar_ret = self::_checkPaopaoyu($uid,15);

				if(false===$ar_ret)
				{
					return false;
				}
				if(1==$ar_ret['result'])
				{
					$ar_ret['msg'] = sprintf(UCConfMedal::$ar_show_info[$medal_id],$ar_ret['level']);
				}
				break;

			case UCConfMedal::MEDAL_KONGLONG_1:
				$ar_ret = self::_checkMedal($uid,$medal_id,MEDAL_REQUEST_KONGLONG,UCConfMedal::MEDAL_KONGLONG_KEY);

				if(false===$ar_ret)
				{
					return false;
				}
				if(1==$ar_ret['result'])
				{
					$ar_ret['msg'] = sprintf(UCConfMedal::$ar_show_info[$medal_id],$ar_ret['ext']);
				}
				break;

			case UCConfMedal::MEDAL_KONGLONG_2:
				$ar_ret = self::_checkMedal($uid,$medal_id,MEDAL_REQUEST_KONGLONG,UCConfMedal::MEDAL_KONGLONG_KEY);

				if(false===$ar_ret)
				{
					return false;
				}
				if(1==$ar_ret['result'])
				{
					$ar_ret['msg'] = sprintf(UCConfMedal::$ar_show_info[$medal_id],$ar_ret['ext']);
				}
				break;

			case UCConfMedal::MEDAL_KONGLONG_3:
				$ar_ret = self::_checkMedal($uid,$medal_id,MEDAL_REQUEST_KONGLONG,UCConfMedal::MEDAL_KONGLONG_KEY);

				if(false===$ar_ret)
				{
					return false;
				}
				if(1==$ar_ret['result'])
				{
					$ar_ret['msg'] = sprintf(UCConfMedal::$ar_show_info[$medal_id],$ar_ret['ext']);
				}
				break;

			case UCConfMedal::MEDAL_MINGXING_1:
				$ar_ret = self::_checkMedal($uid,$medal_id,MEDAL_REQUEST_MINGXING,UCConfMedal::MEDAL_MINGXING_KEY);

				if(false===$ar_ret)
				{
					return false;
				}
				if(1==$ar_ret['result'])
				{
					$ar_ret['msg'] = sprintf(UCConfMedal::$ar_show_info[$medal_id],$ar_ret['ext']);
				}
				break;

			case UCConfMedal::MEDAL_MINGXING_2:
				$ar_ret = self::_checkMedal($uid,$medal_id,MEDAL_REQUEST_MINGXING,UCConfMedal::MEDAL_MINGXING_KEY);

				if(false===$ar_ret)
				{
					return false;
				}
				if(1==$ar_ret['result'])
				{
					$ar_ret['msg'] = sprintf(UCConfMedal::$ar_show_info[$medal_id],$ar_ret['ext']);
				}
				break;

			case UCConfMedal::MEDAL_MINGXING_3:
				$ar_ret = self::_checkMedal($uid,$medal_id,MEDAL_REQUEST_MINGXING,UCConfMedal::MEDAL_MINGXING_KEY);

				if(false===$ar_ret)
				{
					return false;
				}
				if(1==$ar_ret['result'])
				{
					$ar_ret['msg'] = sprintf(UCConfMedal::$ar_show_info[$medal_id],$ar_ret['ext']);
				}
				break;

			case UCConfMedal::MEDAL_SPECIAL_PLAYBOY:
				$ar_ret = self::_checkSpecialMedal($uid,1);
				if(1==$ar_ret['result'])
				{
					$ar_ret['msg'] = sprintf(UCConfMedal::$ar_show_info[$medal_id],UCConfMedal::$ar_medal_info[$medal_id]['name']);
				}
				break;
			
			case UCConfMedal::MEDAL_SPECIAL_SHOWMAN:
				$ar_ret = self::_checkSpecialMedal($uid,2);
				if(1==$ar_ret['result'])
				{
					$ar_ret['msg'] = sprintf(UCConfMedal::$ar_show_info[$medal_id],UCConfMedal::$ar_medal_info[$medal_id]['name']);
				}
				break;
			
			case UCConfMedal::MEDAL_SPECIAL_SUPERMAN:
				$ar_ret = self::_checkSpecialMedal($uid,3);
				if(1==$ar_ret['result'])
				{
					$ar_ret['msg'] = sprintf(UCConfMedal::$ar_show_info[$medal_id],UCConfMedal::$ar_medal_info[$medal_id]['name']);
				}
				break;

			case UCConfMedal::MEDAL_LIMIT_NEICE:
				$ar_ret['result'] = 2;
				break;

			case UCConfMedal::MEDAL_LIMIT_LONGZHIGU:
				$ar_medal = self::getDoneList($uid);
				$ar_ret = self::_retFunc(5,$ar_medal['done_count']);
				if(1==$ar_ret['result'])
				{
					$ar_ret['msg'] = sprintf(UCConfMedal::$ar_show_info[$medal_id]);
				}
				break;

			case UCConfMedal::MEDAL_LIMIT_BANGBANGTANG:
				if(UCModActiveUser::whetherActiveUser($uid))
				{
					$ar_ret['result'] = 2;
				}
				else
				{
					$ar_ret['result'] = 1;
					$ar_ret['msg'] = sprintf(UCConfMedal::$ar_show_info[$medal_id]);
				}
				break;
		}

		return $ar_ret;
	}

	/**
	 * 检查用户勋章是否完成 
	 * @param	string	$uid		用户ID
	 * @param	int		$num		数量
	 * @param	int		$medal_id	勋章ID
	 * @return	mix					false:error | array('result'=> '1:未完成徽章|2:完成徽章并且入库','param'=>'相关输出辅助信息')
	 *
	 */
	private function _checkSpecialMedal($uid,$num,$base=UCConfMedal::MEDAL_SPECIAL_BASE)
	{
		$medal_list = self::getUserMedalList($uid);
		$ar_num = array();
		foreach ($medal_list['list'] as $key=>$medal) 
		{
			if(UCConfMedal::MEDAL_USER_STATUS_DONEANDHAVE==$medal['medal_status'])
			{
				$ar_num[$medal['type']] += 1; 				
			}
		}
		$i = 0;
		foreach ($ar_num as $key=>$value)
		{
			if(intval($value)>=$num)
			{
				$i++;
			}
		}
		if($i<$base)
		{
			$ar_ret['result'] = 1;
		}
		else
		{
			$ar_ret['result'] = 2;
		}
		return $ar_ret;
	}

	private function _retFunc($need,$total)
	{
		if($total<$need)
		{
			$ar_ret['result'] = 1;
			$ar_ret['need_count']	= $need;
			$ar_ret['total_count']	= $total;
		}
		else
		{
			$ar_ret['result'] = 2;
		}
		return $ar_ret;
	}
	
////////////////////////////////////////////外部接口////////////////////////////////////////////////////////
	
	/**
	 * 检查用户是否完是VIP用户
	 * @param	string	$uid		用户ID
	 * @param	int		$num		数量
	 * @return	bool				true|false	
	 *
	 */
	private function _checkVip($uid,$num)
	{
		$ar_ret = SDOApiVipService::QueryUserInfo($uid,array('VipRank','VipValidDate'));
		if($ar_ret['VipRank']>=$num)
		{
			$ar_ret['result'] = 2;
		}
		else
		{
			$ar_ret['result'] = 1;
		}
		return $ar_ret;
	}

	/**
	 * 检查用户是否完完成潘多拉勋章
	 * @param	string	$uid		用户ID
	 * @param	int		$num		数量
	 * @return	bool				true|false	
	 *
	 */
	private function _checkPanduola($uid,$level)
	{
		$ar_param['uid']	= $uid;
		$ar_param['level']	= $level;
		$ar_param['time']	= time();

		$ar_param['sign']	= md5('level='.$ar_param['level'].'time='.$ar_param['time'].'uid='.$ar_param['uid'].UCConfMedal::MEDAL_PANDUOLA_KEY);
		$ret = get_http_data(MEDAL_REQUEST_PANDUOLA, array('post'=>$ar_param), '', 0, 25);
		//var_dump($ret);
		if(false===$ret)
		{
			self::$error_no = UCConfMedal::MEDAL_ERROR_REQUEST;
			return false;
		}
		$ar_ret = json_decode($ret);
		switch($ar_ret->confirm)
		{
			case 0:
				$key = md5('confirm='.$ar_ret->confirm.'level='.$ar_ret->level.'quantity_needed='.$ar_ret->quantity_needed.'time='.$ar_ret->time.'uid='.$ar_ret->uid.UCConfMedal::MEDAL_PANDUOLA_KEY);
				if($key!=$ar_ret->sign)
				{
					self::$error_no = UCConfMedal::MEDAL_ERROR_ILLEGAL;
					return false;
				}
				$ar_tmp['result'] = 1;
				$ar_tmp['sub'] = $ar_ret->quantity_needed;
				break;

			case 1:
				$key = md5('confirm='.$ar_ret->confirm.'level='.$ar_ret->level.'quantity_needed='.$ar_ret->quantity_needed.'time='.$ar_ret->time.'uid='.$ar_ret->uid.UCConfMedal::MEDAL_PANDUOLA_KEY);
				if($key!=$ar_ret->sign)
				{
					self::$error_no = UCConfMedal::MEDAL_ERROR_ILLEGAL;
					return false;
				}
				$ar_tmp['result'] = 2;
				break;
			
			default:
				self::$error_no = UCConfMedal::MEDAL_ERROR_INTERFACE;
				return false;
				break;
		}
		return $ar_tmp;
	}

	/**
	 * 获取泡泡鱼等级
	 * @param	string	$uid		用户ID
	 * @return	bool				true|false	
	 *
	 */
	private function _getPaopaoyuLevel($uid)
	{
		$ar_param['uid']	= $uid;
		$ar_param['time']	= time();

		$ar_param['sign']	= md5('uid='.$ar_param['uid'].'time='.$ar_param['time'].UCConfMedal::MEDAL_PAOPAOYU_KEY);
		$ret = get_http_data(MEDAL_REQUEST_PAOPAOPYU, array('post'=>$ar_param), '', 0, 25);
		//var_dump($ret);
		if(false===$ret)
		{
			self::$error_no = UCConfMedal::MEDAL_ERROR_REQUEST;
			return false;
		}
		$ar_ret = json_decode($ret);
		switch($ar_ret->confirm)
		{
			case 1:
				$key = md5('uid='.$ar_ret->uid.'time='.$ar_ret->time.'confirm='.$ar_ret->confirm.'level='.$ar_ret->level.UCConfMedal::MEDAL_PAOPAOYU_KEY);
				if($key!=$ar_ret->sign)
				{
					self::$error_no = UCConfMedal::MEDAL_ERROR_ILLEGAL;
					return false;
				}
				break;
			
			default:
				self::$error_no = UCConfMedal::MEDAL_ERROR_INTERFACE;
				return false;
				break;
		}
		return $ar_ret->level;
	}
	
	/**
	 * 检查用户是否完完成泡泡鱼勋章
	 * @param	string	$uid		用户ID
	 * @param	int		$num		数量
	 * @return	bool				true|false	
	 *
	 */
	private function _checkPaopaoyu($uid,$level)
	{
		$num = self::_getPaopaoyuLevel($uid);
		if(false===$num)
		{
			return false;
		}
		if($num>=$level)
		{
			$ar_tmp['result'] = 2;
		}
		else
		{
			$ar_tmp['result'] = 1;
			$ar_tmp['level'] = $num;
		}
		return $ar_tmp;
	}


	/**
	 * 检查用户是否完完成勋章
	 * @param	string	$uid		用户ID
	 * @param	int		$mid		勋章ID
	 * @param	string	$url		勋章请求的URL
	 * @param	string	$key		勋章唯一KEY
	 * @return	mix				
	 *
	 */
	private function _checkMedal($uid,$mid,$url,$key)
	{
		$ar_param['uid']	= $uid;
		$ar_param['mid']	= $mid;
		$ar_param['time']	= time();

		$ar_param['sign']	= md5('uid='.$ar_param['uid'].'time='.$ar_param['time'].'mid='.$ar_param['mid'].$key);
		$ret = get_http_data($url, array('post'=>$ar_param), '', 0, 5);
		//var_dump($ret);
		if(false===$ret)
		{
			self::$error_no = UCConfMedal::MEDAL_ERROR_REQUEST;
			return false;
		}
		$ar_ret = json_decode($ret);
		switch($ar_ret->confirm)
		{
			case 0:
				$key = md5('uid='.$ar_ret->uid.'time='.$ar_ret->time.'mid='.$ar_ret->mid.'confirm='.$ar_ret->confirm.$key);
				if($key!=$ar_ret->sign)
				{
					self::$error_no = UCConfMedal::MEDAL_ERROR_ILLEGAL;
					return false;
				}
				$ar_tmp['result'] = 1;
				$ar_tmp['ext'] = $ar_ret->ext;
				break;

			case 1:
				$key = md5('uid='.$ar_ret->uid.'time='.$ar_ret->time.'mid='.$ar_ret->mid.'confirm='.$ar_ret->confirm.$key);
				if($key!=$ar_ret->sign)
				{
					self::$error_no = UCConfMedal::MEDAL_ERROR_ILLEGAL;
					return false;
				}
				$ar_tmp['result'] = 2;
				break;
			
			default:
				self::$error_no = UCConfMedal::MEDAL_ERROR_INTERFACE;
				return false;
				break;
		}
		return $ar_tmp;
	}
}
?>